package org.wekit.engine.pvm.process;

import java.util.ArrayList;
import java.util.List;

import org.wekit.engine.pvm.ExecutionListener;
import org.wekit.engine.pvm.PvmTransition;

/**
 * 流程路由定义类
 * @author HuangWeili
 *
 */
public class Transition extends ProcessElement implements PvmTransition {

	private static final long serialVersionUID = -5849545466027478341L;

	protected Activity source;
	
	protected Activity destination;

	//定义流程监听事件
	protected List<ExecutionListener> executionListeners;
	
	
	public Transition(String id, ProcessDefinition processDefinition) {
		super(id, processDefinition);
	}

	
	public void addExecutionListener(ExecutionListener executionListener){
		if(null==executionListeners){
			this.executionListeners=new ArrayList<ExecutionListener>();
		}
		this.executionListeners.add(executionListener);
	}
	
	public String toString(){
		return "("+source.getId()+")--"+(id!=null?id+"-->(":">(")+destination.getId()+")";
	}
	
	/**
	 * 返回执行监听
	 * @return
	 */
	public List<ExecutionListener> getExecutionListeners(){
		if(executionListeners==null){
			return new ArrayList<ExecutionListener>();
		}
		return executionListeners;
	}
	
	/**
	 * 设置执行监听
	 * @param executionListeners
	 */
	public void setExecutionListeners(List<ExecutionListener> executionListeners){
		this.executionListeners=executionListeners;
	}
	
	public void setSource(Activity source)
	{
		this.source=source;
	}
	
	
	@Override
	public Activity getSource() {
		// TODO Auto-generated method stub
		return this.source;
	}

	public void setDestination(Activity destination){
		this.destination=destination;
		destination.getIncomingTransitions().add(this);
	}
	
	
	@Override
	public Activity getDestination() {
		// TODO Auto-generated method stub
		return this.destination;
	}

}
